#ifndef ___SERVER___
#define ___SERVER___
#include <func.h>
#include <sys/sendfile.h>
#include <crypt.h>
#define STR_LEN 10 //定义随机输出的字符串长度。
#define _XOPEN_SOURCE


//传递文件时的“车厢”结构体
typedef struct train_s
{
    int length;
    char data[1024];
} train_t;

//功能函数各类worker使用的结构体
typedef struct azu_factory_s
{
    char server_path[1024]; // 服务端实际路径
    char client_path[1024]; // 客户端看见的虚拟路径
    char input_path[1024];  // 用户输入的“命令 路径/文件”中的的路径/文件
    char command[8];        // 命令
    MYSQL *server_db;       // 数据库句柄
    char username[1024];    // 用户名
} azu_factory_t;

// 日志宏函数
#define LOG_OPERATION()                                                      \
    {                                                                        \
        time_t now = time(NULL);                                             \
        syslog(LOG_INFO, "操作:%s\n     "                                  \
                         "时间:%s\n     "                                  \
                         "代码行号:%d\n     "                            \
                         "代码文件名:%s\n     "                         \
                         "代码所在函数%s\n     ",                            \
               __FUNCTION__, ctime(&now), __LINE__, __FILE__, __FUNCTION__); \
        closelog();                                                          \
    }

int s_login(int netfd, MYSQL* mysql, int* isLogin);
int worker_cd(int netfd, azu_factory_t *factor);
int worker_gets_server(int netfd, azu_factory_t *factor);
int worker_puts_server(int netfd, azu_factory_t *factor);
int worker_ls(int netfd, azu_factory_t *factor);
int worker_pwd(int netfd, azu_factory_t *factor);
int worker_remove(int netfd, azu_factory_t *factor);
int worker_mkdir(int netfd, azu_factory_t *factor);
int worker_rmdir(int netfd, azu_factory_t *factor);
int worker_rmdir_helper(const char *pathname);
int server_worker(int netfd, MYSQL *mysql);
int command_execute(int netfd, azu_factory_t *factor);

#endif